package com.aloda.controller.user;

import com.aloda.dto.AddressAddDTO;
import com.aloda.result.Result;
import com.aloda.service.AddressService;
import com.aloda.vo.AddressInfoVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/address")
@Slf4j
public class AddressController {

    @Autowired
    private AddressService addressService;

    /**
     * 新增地址
     * @param addressAddDTO
     * @return
     */
    @PostMapping("/add")
    public Result addAddress(@RequestBody AddressAddDTO addressAddDTO){
        log.info("新增地址：{}",addressAddDTO);
        addressService.addAddress(addressAddDTO);
        return Result.success();
    }

    /**
     * 获取地址信息
     * @return
     */
    @GetMapping("/list")
    public Result<List<AddressInfoVO>> queryAddress(){
        List<AddressInfoVO> list = addressService.queryAddress();
        return Result.success(list);
    }
}
